package user

import (
	"context"
	"encoding/json"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logc"
	"github.com/zeromicro/go-zero/core/logx"
)

type EnumLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 会员模块 - 枚举
func NewEnumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EnumLogic {
	return &EnumLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *EnumLogic) Enum(req *types.EnumRequest) (resp *types.EnumResponse, err error) {
	result, err := l.svcCtx.UserServiceRPC.Enum(l.ctx, nil)
	if err != nil {
		logc.Error(l.ctx, err)
		return nil, err
	}

	tmp, err := json.Marshal(result)
	if err != nil {
		logc.Error(l.ctx, err)
		return nil, err
	}

	var r types.EnumResponse
	json.Unmarshal(tmp, &r)
	resp = &r
	return
}
